package com.yanzq.service.impl;

import com.yanzq.dao.DataRead;
import com.yanzq.dao.impl.DataReadImplements;
import com.yanzq.pojo.User;
import com.yanzq.service.UserService;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

public class UserServiceImplements implements UserService {
    private DataRead userData = new DataReadImplements();
    @Override
    public List<User> getInfo() {
        List<String> data = userData.readFile();
        List<User> result = data.stream().map((line)->{
            String[] users = line.split(",");
            int id = Integer.parseInt(users[0]);
            String name = users[1];
            int age = Integer.parseInt(users[2]);
            LocalDateTime lastUpdate = LocalDateTime.parse(users[3], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            return new User(id, name, age, lastUpdate);
        }).toList();
        return result;
    }
}
